package com.sctvcloud.zhaohua_sd.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.zhaohua_sd.R;
import com.sctvcloud.zhaohua_sd.beans.NewsItem;
import com.sctvcloud.zhaohua_sd.ui.utils.GlideUtil;
import com.sctvcloud.zhaohua_sd.utils.TimeUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/4 0004.
 */

public class HomeHotVideoContentHolder extends BaseRecylerHolder<NewsItem> implements View.OnClickListener {
    @BindView(R.id.item_home_hot_video_con_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_home_hot_video_con_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_home_hot_video_con_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_home_hot_video_con_type)
    protected ImageView type_iv;
    /**
     * 是否只有一个
     */
    private boolean isOnly;

    private CustomEXImageView.InternalRatio ratio;

    public HomeHotVideoContentHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
//        CustomEXImageView.IRatio ir = img.getRatio();
//        ratio = new CustomEXImageView.InternalRatio(16, 9);
//        img.setOuterRatioType(-1, ratio);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }

    @Override
    public void setData(NewsItem newsItem) {
        title.setText(!TextUtils.isEmpty(newsItem.getNewsTitle()) ? newsItem.getNewsTitle() : "");
        if (!TextUtils.isEmpty(newsItem.getNewsImage())) {
            GlideUtil.getGlideWithLarge169Def(context, newsItem.getNewsImage()).into(img);
        } else {
            img.setImageResource(R.mipmap.icon_def_16_9_s);
        }
        if (newsItem.getNewsType() == 2) { //音频
            type_iv.setImageResource(R.mipmap.icon_home_voice);
            type_iv.setVisibility(View.VISIBLE);
        } else if (newsItem.getNewsType() == 3) {   //视频
            type_iv.setImageResource(R.mipmap.icon_home_play);
            type_iv.setVisibility(View.VISIBLE);
        } else {
            type_iv.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(newsItem.getNewsMediaLength())) {
            time.setVisibility(View.VISIBLE);
            time.setText(TimeUtils.formatTimeToHM(newsItem.getNewsMediaLength()));
        } else {
            time.setVisibility(View.GONE);
        }

    }

    public HomeHotVideoContentHolder setOnly(boolean only) {
        isOnly = only;
        return this;
    }
}
